using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
using System.Xml;

namespace DAOLayer
{
    public class DataProvider
    {

        public SqlConnection strCnn;
        public void connect()
        {
            String file = AppDomain.CurrentDomain.BaseDirectory + "QuanLyBoMon\\Connectring.xml";
            string cn = DocXML(file);
            strCnn = new SqlConnection (cn);
            strCnn.Open();

        }
        
        public static string DocXML(string fileName)
        {
            string connect="";
            XmlDocument TaiLieu = new XmlDocument();
            
            XmlElement goc = TaiLieu.DocumentElement;
            try
            {
                TaiLieu.Load(fileName);
                goc = TaiLieu.DocumentElement;
                connect = goc.GetAttribute("string");
                return connect;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            return null;
        }

        public void disconnect()
        {
            strCnn.Close();
        }

        protected ArrayList ConvertDataSetToArrayList(DataSet dataset)
        {
            ArrayList arr = new ArrayList();
            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            for (i = 0; i < n; i++)
            {
                object hs = GetDataFromDataRow(dt, i);
                arr.Add(hs);

            }
            return arr;
        }

        protected virtual object GetDataFromDataRow(DataTable dt, int i)
        {
            return null;
        }
    }
}
